package config

import (
	"fmt"
	"gopkg.in/yaml.v2"
	"log"

	"os"
	"ylb/tool"
)

func defaultUrlConfig() tool.Url {
	return tool.Url{
		Host:     "124.221.212.162",
		Port:     3306,
		Username: "ynote",
		Password: "ylb305042026",
		DataBase: "ynote",
	}
}
func GetDBUrlConfig() tool.Url {

	open, err := os.Open("./config/db.yaml")
	defer open.Close()
	if err != nil {
		log.Println("%v\n", "读取db.yaml失败")
		return defaultUrlConfig()

	}
	decoder := yaml.NewDecoder(open)

	m := tool.Url{}
	err = decoder.Decode(&m)
	fmt.Printf("%v\n", m)
	if err != nil {
		log.Println("%v\n", "解析db.yaml失败")
		return defaultUrlConfig()
	}

	return m

}
